home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / By the Book / Mac C Primer V2 / Primer II Changes 4.0 to 5.0
Text File  |  1994-08-27  |  8KB  |  307 lines

  1. To move the Primer II code up to THINK 5 or THINK 6, read this errata sheet. To move it up to THINK 7+, you should also read the errata sheet entitled "Primer, THINK 6->THINK 7.w", which will take you through the changes to Primer, Vol I. You'll need to make the same basic changes here. Unfortunately, getting the starter code to run under TCL 2.0 is too major a change. I'd just read chapter 6 and ignore the code, then read "Learn C++ on the Macintosh" to get started with C++. By the way, I've included a few of my MacTech columns that deal with rewrites of Primer II code...
  2.  
  3. Dave
  4.  
  5. -----------------
  6.  
  7. cdev.c:
  8. 1)    Insert line, just after #defines:
  9.         short    FindFontNumber();
  10.  
  11.  
  12. Tester.c:
  13. 1)    Replace #define MOVE_TO_FRONT from
  14.         -1L
  15.     to
  16.         (WindowPtr)-1L
  17.  
  18. 2) Change BeginUpdate( gTheEvent.message ) to
  19.             BeginUpdate( (WindowPtr)gTheEvent.message )
  20.  
  21. 3) Change EndUpdate( gTheEvent.message ) to
  22.             EndUpdate( (WindowPtr)gTheEvent.message )
  23.  
  24.  
  25. DLOG.c:
  26. 1)    Replace #define MOVE_TO_FRONT from
  27.         -1L
  28.     to
  29.         (WindowPtr)-1L
  30.  
  31.  
  32. ColorInfo.c:
  33. 1) Replace the line:
  34.         #include "ColorToolbox.h"
  35.     with
  36.         #include "Picker.h"
  37.  
  38.  
  39. Palette.c:
  40. 1) Replace the line:
  41.         #include "ColorToolbox.h"
  42.     with the two lines:
  43.         #include "Palettes.h"
  44.         #include "Picker.h"
  45.         
  46. 2)    Replace #define MOVE_TO_FRONT from
  47.         -1L
  48.     to
  49.         (WindowPtr)-1L
  50.  
  51.  
  52. ColorTutor.c:
  53. 1) Replace the line:
  54.         #include "ColorToolbox.h"
  55.     with the two lines:
  56.         #include "Palettes.h"
  57.         #include "Picker.h"
  58.         
  59. 2)    Replace #define MOVE_TO_FRONT from
  60.         -1L
  61.     to
  62.         (WindowPtr)-1L
  63.  
  64.  
  65. GWorld.c:
  66. 1) Replace the two lines:
  67.         #include "ColorToolbox.h"
  68.         #include "QuickDraw32Bit.h"
  69.     with the two lines:
  70.         #include "Picker.h"
  71.         #include "QDOffscreen.h"
  72.         
  73. 2) Replace #define MOVE_TO_FRONT from
  74.         -1L
  75.     to
  76.         (WindowPtr)-1L
  77.         
  78.  
  79. FormEdit.c:
  80. 1) In the function DoTEKey(), replace the line:
  81.         tempStr[ i+1 ] = (*text)[ i ];
  82.     with the line:
  83.         tempStr[ i+1 ] = (*(char **)text)[ i ];
  84.         
  85. 2) In the function HandleEditChoice(), replace the line:
  86.         tempStr[ i+1 ] = (*text)[ i ];
  87.     with the line:
  88.         tempStr[ i+1 ] = (*(char **)text)[ i ];
  89.         
  90. 3) Replace #define MOVE_TO_FRONT from
  91.         -1L
  92.     to
  93.         (WindowPtr)-1L
  94.         
  95. 4) In the function NewClikLoop(), replace the declaration:
  96.         int            amount;
  97.     with the line:
  98.         short            amount;
  99.  
  100.  
  101. Starter.π:
  102. 1) Make a copy of the "Starter Folder" found in the "TCL 1.1 Demos" folder in your
  103.     "Development" folder.  Next, copy the following files from your old "MyStarter"
  104.     folder into this new folder:
  105.         - CDragPane.c
  106.         - CDragPane.h
  107.         - CMouse.c
  108.         - CMouse.h
  109.         - CStarterApp.c
  110.         - CStarterApp.h
  111.         - CStarterDoc.c
  112.         - CStarterApp.h
  113.         - CStarterPane.c
  114.         - CStarterPane.h
  115.         - Starter.c
  116.     You should be copying 11 files, replacing their counterparts in the new folder.
  117.     Start up THINK C by double-clicking the file Starter.π in this new folder.
  118.     
  119. 2) Select Options... from the Edit menu.  
  120.     Select "Language Settings" from the popup menu.
  121.     Make sure that the "Language Extensions" check box is checked.
  122.     Select the "THINK C + Objects" radio button.
  123.     Make sure the "Strict Prototype Enforcement" check box is checked.
  124.     Select the "Infer Prototypes" radio button.
  125.  
  126. 3) Edit each of the functions in the files CDragPane.c, CMouse.c, and
  127.     CStarterPane.c.  Change each function's parameter declarations from
  128.     the old style to the new style of parameter declaration.  Old style
  129.     declarations look like this:
  130.         void CDragPane::DoClick( hitPt, modifierKeys, when )
  131.         Point        hitPt;
  132.         short        modifierKeys;
  133.         long        when;
  134.         {
  135.         }
  136.     New style declarations look like this:
  137.         void CDragPane::DoClick( Point hitPt, short modifierKeys, long when )
  138.         {
  139.         }
  140.  
  141. 4) In the file CDragPane.c, in the function IDragPane,
  142.     change the declaration:
  143.         Rect r;
  144.     to
  145.         LongRect r;
  146.         
  147. 5) Also in CDragPane.c, in the function DoClick, change the first
  148.     five lines from:
  149.         Rect    r;
  150.         Rect    endLocation;
  151.         
  152.         r = frame;
  153.         EraseRect( &r );
  154.         
  155.         FrameToEnclR(&r);
  156.     to these eight lines:
  157.         Rect    r;
  158.         Rect    endLocation;
  159.         LongRect    longR;
  160.         
  161.         FrameToQDR( &frame, &r );
  162.         EraseRect( &r );
  163.         
  164.         QDToLongRect(&r,&longR);
  165.         FrameToEnclR(&longR);
  166.         LongToQDRect( &longR, &r );
  167.  
  168. 6) In the file CMouse.h, change the three lines:
  169.         void        BeginTracking( Point *startPt );
  170.         void        KeepTracking( Point *currPt, Point *prevPt, Point *startPt );
  171.         void        EndTracking( Point *currPt, Point *prevPt, Point *startPt );
  172.     to:
  173.         void        BeginTracking( struct LongPt *startPt );
  174.         void        KeepTracking( struct LongPt *currPt, struct LongPt *prevPt,
  175.                                     struct LongPt *startPt );
  176.         void        EndTracking( struct LongPt  *currPt, struct LongPt  *prevPt,
  177.                                     struct LongPt  *startPt );
  178.  
  179. 7) In the file CMouse.c, in the function IMouse(), change the declaration:
  180.         Rect r;
  181.     to
  182.         LongRect r;
  183.  
  184. 8) Also in the file CMouse.c, in the function IMouse(), change:
  185.         theBounds = r;
  186.     to
  187.         LongToQDRect( &r, &theBounds );
  188.  
  189. 9) Also in the file CMouse.c, in the function BeginTracking(), change the
  190.     function declaration from:
  191.         void CMouse::BeginTracking( Point *startPt )
  192.     to
  193.         void CMouse::BeginTracking( struct LongPt *startPt )
  194.  
  195. 10) Also in the file CMouse.c, replace the function KeepTracking() with the following:
  196.  
  197. void CMouse::KeepTracking( struct LongPt *currPt, struct LongPt *prevPt,
  198.                                             struct LongPt *startPt )
  199. {
  200.     LongRect    r, f;
  201.     Rect        shortR;
  202.     long        curTicks;
  203.     LongPt        startPosit, newPosit, cp, pp;
  204.     RgnHandle    clipRgn;
  205.     
  206.     thePanorama->GetPosition( &startPosit );
  207.     
  208.     clipRgn = NewRgn();
  209.     
  210.     if ( thePanorama->AutoScroll( currPt )
  211.             || ! EqualLongPt( currPt, prevPt ) )
  212.     {
  213.         thePanorama->GetPosition( &newPosit );
  214.         
  215.         GetClip( clipRgn );
  216.         QDToLongRect( &((**clipRgn).rgnBBox), &r );
  217.         OffsetLongRect( &r, startPosit.h - newPosit.h,
  218.                 startPosit.v - newPosit.v );
  219.                 
  220.         thePanorama->GetFrame(&f);
  221.         PinInRect(&f, (LongPt *)(&(r.top)));
  222.         PinInRect(&f, (LongPt *)(&(r.bottom)));
  223.         
  224.         LongToQDRect( &r, &shortR );
  225.         ClipRect( &shortR );
  226.         
  227.         shortR = theLocation;    /* Erase old gray rect */
  228.         
  229.         curTicks = TickCount();
  230.         while ( curTicks == TickCount() ) ;
  231.         FrameRect( &shortR );
  232.         QDToLongRect( &shortR, &r );
  233.         
  234.         cp = *currPt;
  235.         pp = *prevPt;
  236.         QDToLongRect( &theBounds, &f );
  237.         PinInRect(&f, &cp);
  238.         PinInRect(&f, &pp);
  239.  
  240.         OffsetLongRect(&r, cp.h - pp.h, cp.v - pp.v);    
  241.             
  242.         SetClip( clipRgn );
  243.         
  244.         curTicks = TickCount();
  245.         while ( curTicks == TickCount() ) ;
  246.         
  247.         LongToQDRect( &r, &shortR );
  248.         FrameRect( &shortR );                /* Draw new gray rect */
  249.         theLocation = shortR;        /* update theLocation instance var */
  250.     }
  251.     
  252.     DisposeRgn( clipRgn );
  253. }
  254.         
  255.         
  256. 11) Replace the declaration of the function EndTracking() with:
  257.  
  258. void CMouse::EndTracking( struct LongPt  *currPt, struct LongPt  *prevPt,
  259.                                     struct LongPt  *startPt )
  260.  
  261. 12) In the file CStarterApp.c, replace the line:
  262.         CApplication::IApplication(4, 20480L, 2048L);
  263.     with the line:
  264.         CApplication::IApplication(4, 20480L, 20480L, 20480L);
  265.  
  266. 13) Add these three lines to the list of include files in the file
  267.     CStarterDoc.c:
  268.         
  269. #include "TBUtilities.h"
  270. #include "CWindow.h"
  271. #include <Packages.h>
  272.  
  273. 14) In the file CStarterDoc.c, in the function OpenFile(), replace the line:
  274.         theError = theFile->Open(fsRdWrPerm);
  275.     with the line
  276.         theFile->Open(fsRdWrPerm);
  277.         
  278. 15) In the file CStarterDoc.c, in the function OpenFile(), comment
  279.     out each of the lines:
  280.         gApplication->RequestMemory(FALSE, TRUE);
  281.         theFile->ReadAll(&theData);
  282.     and
  283.         gApplication->RequestMemory(FALSE, FALSE);
  284.  
  285. 16) In the file CStarterDoc.c, in the function BuildWindow(), change the line:
  286.         Rect            panFrame;
  287.     to
  288.         LongRect            panFrame;
  289.         
  290. 17) In the file CStarterPane.c, in the function DoDrag(), change the declaration:
  291.         Rect        boundsRect;
  292.     to
  293.         LongRect        boundsRect;
  294.  
  295. 18) In the file CStarterPane.c, in the function DoDrag(), add the declaration:
  296.         LongPt        longP;
  297.         
  298. 19) In the file CStarterPane.c, in the function DoDrag(), change the line:
  299.         TrackMouse( aMouseTask, p, &boundsRect );
  300.     to
  301.         QDToLongPt( p, &longP );
  302.         TrackMouse( aMouseTask, &longP, &boundsRect );
  303.  
  304.  
  305. ShowINIT.c:
  306. 1) Delete the line:
  307.         #include <Color.h>